package com.shadt.cloud.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shadt.cloud.service.BranchChannelService;
import com.shadt.cloud.service.BranchService;
import com.shadt.cloud.vo.BranchVo;
import com.shadt.core.controller.BaseController;
import com.shadt.core.model.Json;

/**
 * 平台栏目权限
 * 
 * @author SongR
 *
 */
@Controller
@RequestMapping(value = "/branchchannel")
public class BranchChannelController extends BaseController {
	@Autowired
	BranchChannelService service;

	@Autowired
	BranchService bservice;

	/**
	 * 注册栏目权限
	 * 
	 * @param request
	 * @param appname
	 * @param key
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/register", method = { RequestMethod.GET, RequestMethod.POST })
	public Json register(HttpServletRequest request, String appname, String keys) {
		Json j = new Json();
		String[] key = new String[1];
		if(null!=keys&&!"".equals(keys)){
			key= keys.split(",");
		}
		BranchVo bvo = new BranchVo();
		try {
			bvo = bservice.getBranch(appname);
			bvo.setSecret(null);
		} catch (Exception e) {
		}
		for (String s : key) {
			if(null!=s||!"".equals(s))
				service.add(bvo.getId().toString(), s);
		}
		j.setMsg("本次共申请"+key.length+"个栏目权限！");
		j.setSuccess(true);
		return j;
	}
}
